job SerialRender(list inputs) {
  int orig = (int)inputs[0];

  for (int c = 0; c < 1000; c = c + 1) {
    int i = c + orig;
    float f = (float)(i-500) / 100.0;
    string fname = "%03d" % [i];
    @{"./raytrace.out %s.ppm %lf" % [fname, f]};
    @{"convert %s.ppm %s.jpg" % [fname, fname]};
    @{"rm -f %s.ppm" % [fname]};
  }
}

void main(list args) {
  // list my_servers = loadcsv "servers.csv";
  list my_servers = [["user" => "dummy",
                      "host" => "localhost",
                      "password" => "dummypw"]];
  list common = [(file)"raytrace.out"];
  list inputs = [[0]];

  connect my_servers;

  list output;
  int render_job = push SerialRender, common, inputs, output;
  wait render_job;

  for (int i = 0; i < length output; i = i + 1) {
    map out = (map)output[i];
    for (int j = 0; j < length (list)out["files"]; j = j + 1) {
      @{"mv %s/%s %s" % [(string)out["root"], (string)((list)out["files"])[j]]};
    }
  }

  @{"ffmpeg -i %03d.jpg test.mp4"};
}
